package com.sinothk.fc.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sinothk.fc.app.entity.AppStoreServicesEntity;
import com.sinothk.fc.app.service.IAppStoreServicesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

 /**
 * @Description: 门店经营服务表
 * @Author: Liangyt
 * @Date:   2022-09-23
 * @Version: V1.0
 */
@Api(tags="门店经营服务表")
@RestController
@RequestMapping("/fc/appStoreServicesCtrl")
@Slf4j
public class AppStoreServicesController {

	private final IAppStoreServicesService appStoreServicesService;

	 public AppStoreServicesController(IAppStoreServicesService appStoreServicesService) {
		 this.appStoreServicesService = appStoreServicesService;
	 }

	 /**
	 * 分页列表查询
	 *
	 * @param appStoreServices
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-分页列表查询")
	@ApiOperation(value="门店经营服务表-分页列表查询", notes="门店经营服务表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(AppStoreServicesEntity appStoreServices,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<AppStoreServicesEntity> queryWrapper = QueryGenerator.initQueryWrapper(appStoreServices, req.getParameterMap());
		Page<AppStoreServicesEntity> page = new Page<AppStoreServicesEntity>(pageNo, pageSize);
		IPage<AppStoreServicesEntity> pageList = appStoreServicesService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param appStoreServices
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-添加")
	@ApiOperation(value="门店经营服务表-添加", notes="门店经营服务表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody AppStoreServicesEntity appStoreServices) {
		appStoreServicesService.save(appStoreServices);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param appStoreServices
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-编辑")
	@ApiOperation(value="门店经营服务表-编辑", notes="门店经营服务表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody AppStoreServicesEntity appStoreServices) {
		appStoreServicesService.updateById(appStoreServices);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-通过id删除")
	@ApiOperation(value="门店经营服务表-通过id删除", notes="门店经营服务表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		appStoreServicesService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-批量删除")
	@ApiOperation(value="门店经营服务表-批量删除", notes="门店经营服务表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.appStoreServicesService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "门店经营服务表-通过id查询")
	@ApiOperation(value="门店经营服务表-通过id查询", notes="门店经营服务表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		AppStoreServicesEntity appStoreServices = appStoreServicesService.getById(id);
		if(appStoreServices==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(appStoreServices);
	}
}
